/*
 * @(#)PagerInfoPlugIn.java $version 2010. 8. 11
 *
 * Copyright 2007-2010 NHN Corp. All rights Reserved. 
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nhncorp.usf.core.plugin;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.nhncorp.lucy.common.plugin.AbstractPlugIn;
import com.nhncorp.lucy.common.plugin.PlugInException;
import com.nhncorp.lucy.common.util.XMLDOMUtil;
import com.nhncorp.usf.core.config.PagerConfigInfo;
import com.nhncorp.usf.core.config.PagerConfigInfos;

/**
 * Configuration의 Pager정보를 읽어 {@link PagerConfigInfos}를 생성.
 *
 * @author Web Platform Development Team
 */
public class PagerInfoPlugIn extends AbstractPlugIn {

    /**
     *
     * @param node the Node
     * @return boolean the parsing success
     * @throws PlugInException the PlugInException
     */                                   
    @SuppressWarnings("deprecation")
    @Override
    public boolean build(Node node) throws PlugInException {
        PagerConfigInfos.clear();
        NodeList pagers = XMLDOMUtil.getNodes(node, "usf:pagers/usf:pager");

        for (int idx = 0; idx < pagers.getLength(); idx++) {
            Node pager = pagers.item(idx);

            // type
            PagerConfigInfo pagerConfigInfo = new PagerConfigInfo();
            pagerConfigInfo.setType(XMLDOMUtil.getValue(pager, "@type", "default"));

            // size
            pagerConfigInfo.setPageSize(Integer.parseInt(XMLDOMUtil.getValue(pager, "usf:page-size", "10")));
            pagerConfigInfo.setIndexSize(Integer.parseInt(XMLDOMUtil.getValue(pager, "usf:index-size", "10")));

            pagerConfigInfo.setStepType(XMLDOMUtil.getValue(pager, "usf:step-type", "index"));
            pagerConfigInfo.setFirst(XMLDOMUtil.getValue(pager, "usf:first", ""));
            pagerConfigInfo.setFirstAtagAttribute(XMLDOMUtil.getValue(pager, "usf:first/@atag-attribute", ""));
            pagerConfigInfo.setPrev(XMLDOMUtil.getValue(pager, "usf:prev", ""));
            pagerConfigInfo.setPrevAtagAttribute(XMLDOMUtil.getValue(pager, "usf:prev/@atag-attribute", ""));
            pagerConfigInfo.setNext(XMLDOMUtil.getValue(pager, "usf:next", ""));
            pagerConfigInfo.setNextAtagAttribute(XMLDOMUtil.getValue(pager, "usf:next/@atag-attribute", ""));
            pagerConfigInfo.setLast(XMLDOMUtil.getValue(pager, "usf:last", ""));
            pagerConfigInfo.setLastAtagAttribute(XMLDOMUtil.getValue(pager, "usf:last/@atag-attribute", ""));
            pagerConfigInfo.setFirstOff(XMLDOMUtil.getValue(pager, "usf:first-off", ""));
            pagerConfigInfo.setPrevOff(XMLDOMUtil.getValue(pager, "usf:prev-off", ""));
            pagerConfigInfo.setNextOff(XMLDOMUtil.getValue(pager, "usf:next-off", ""));
            pagerConfigInfo.setLastOff(XMLDOMUtil.getValue(pager, "usf:last-off", ""));
            pagerConfigInfo.setIndex(XMLDOMUtil.getValue(pager, "usf:index", ""));
            pagerConfigInfo.setIndexAtagAttribute(XMLDOMUtil.getValue(pager, "usf:index/@atag-attribute", ""));
            pagerConfigInfo.setCurrent(XMLDOMUtil.getValue(pager, "usf:current", ""));
            pagerConfigInfo.setCurrentAtagAttribute(XMLDOMUtil.getValue(pager, "usf:current/@atag-attribute", ""));
            pagerConfigInfo.setSeperator(XMLDOMUtil.getValue(pager, "usf:seperator", ""));

            PagerConfigInfos.put(pagerConfigInfo.getType(), pagerConfigInfo);
        }

        return true;
    }

    /**
     *
     * @throws PlugInException the PlugInException
     */
    @Override
    public void destroy() throws PlugInException {
        PagerConfigInfos.clear();
    }
}
